const express = require('express');
const router = express.Router();
const couponController = require('../controllers/couponController');
const { authenticate } = require('../middleware/authMiddleware');

// 添加路由日志中间件
router.use((req, res, next) => {
  console.log(`Coupon Route: ${req.method} ${req.originalUrl}`);
  next();
});

// 公开接口 - 获取所有可用优惠券
router.get('/', couponController.getAllCoupons);

// 公开接口 - 获取优惠券详情
router.get('/:id', couponController.getCouponById);

// 需要登录的接口 - 购买优惠券
router.post('/:couponId/purchase', authenticate, couponController.purchaseCoupon);

// 需要登录的接口 - 处理优惠券支付成功
router.post('/payment/:orderId/success', authenticate, couponController.handleCouponPayment);

// 需要登录的接口 - 获取用户的优惠券列表
router.get('/user/list', authenticate, couponController.getUserCoupons);

// 需要登录的接口 - 获取优惠券中心列表(包含更多优惠券信息)
router.get('/center/list', authenticate, couponController.getCouponCenter);

// 需要登录的接口 - 领取优惠券(有些优惠券是免费领取的)
router.post('/claim', authenticate, couponController.claimCoupon);

// 需要登录的接口 - 券码验证
router.post('/verify', authenticate, couponController.verifyCoupon);

// 需要登录的接口 - 修改状态
router.post('/updateStatus', authenticate, couponController.updateStatus);
module.exports = router; 